require.config({
    baseUrl: baseUrl
});

define(function(require) {
    var $ = require('jquery');
    window.$ = window.jQuery = $;
    var dialog = require('bDialog/dialog');
    window.dialog=dialog;
    var c = require('../common');
    require('webui');
    require('MobileSlider');
    
    $(function() {
        c.init();

        //图片截取
        $('.pic88 img').imageZoom(88,88);

        if($(".banner").length){
            $(".banner").MobileSlider({width:640,height:320,during:3000});
        }

        //公告
        $('#callboard').callboard(2000);

        //领取优惠券
        $('.coupon .receive').click(function(){
            var t = $(this);
            var id = t.data('id');
            if(empty(id)){
                c.error('请选择操作项!',2000);
                return false;
            }
            $.post(URL+"/receive",{'id':id},function(data){
                if(data.status == 1){
                    c.success(data.info,1000,function(){
                        t.removeClass('btn-orange').removeClass('receive').addClass('btn-disabled').html('已领取');
                    });
                    return true;
                }else{
                    c.error(data.info,2000);
                    return false;
                }
            });
        });

        //收藏
        $('.header .fav').click(function(event) {
            var t = $(this);
            var id = $('input[name="shop_id"]').val();
            if(empty(id)){
                c.error('店铺ID为空!',2000);
                return false;
            }
            $.post(URL+"/collection",{'id':id},function(data){
                if(data.status == 1){
                    t.find('i').addClass('icon-unlove').removeClass('icon-love');
                    c.success('收藏成功',1000);
                    return true;
                }else if(data.status == 2){
                    t.find('i').addClass('icon-love').removeClass('icon-unlove');
                    c.success('取消收藏成功',1000);
                    return true;
                }else{
                    c.error(data.info,2000);
                    return false;
                }
            });
        });

        //打电话弹窗
        $('.botel').click(function(event) {
            openDialog();
        });
        $('.listDialog').delegate('.cancelBtn', 'click', function(event) {
            var bh=$('.listDialog').outerHeight(true);
            closedDialog(bh);
        });
        $('body').delegate('.dialogMask', 'click', function(event) {
            var bh=$('.listDialog').outerHeight(true);
            closedDialog(bh);
        });

        //打开弹窗
        function openDialog(){
            $('.listDialog').show().animate({'bottom': '0px'}, 300);
            $('.dialogMask').show();
        }

        //关闭弹窗
        function closedDialog(h){
            $('.listDialog').animate({'bottom': -h+'px'}, 300,function(){$(this).hide()});
            $('.dialogMask').hide();
        }
    });
});